# -*- coding: utf-8 -*-

# Scrapy settings for scrapy_gif project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
#     https://doc.scrapy.org/en/latest/topics/settings.html
#     https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
#     https://doc.scrapy.org/en/latest/topics/spider-middleware.html
import os
import datetime

BOT_NAME = 'scrapy_gif'

SPIDER_MODULES = ['scrapy_gif.spiders']
NEWSPIDER_MODULE = 'scrapy_gif.spiders'

# Crawl responsibly by identifying yourself (and your website) on the user-agent
# USER_AGENT = 'scrapy_gif (+http://www.yourdomain.com)'

project_dir = os.path.abspath(os.path.dirname(__file__))

# Crawl responsibly by identifying yourself (and your website) on the user-agent
USER_AGENT = '''
               Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) 
               AppleWebKit/604.1.38 (KHTML, like Gecko) 
               Version/11.0 Mobile/15A372 Safari/604.1
             '''

# 是否启用logging 默认: True
LOG_ENABLED = True
# logging使用的编码 默认: 'utf-8'
# LOG_ENCODING = 'utf-8'
# log CRITICAL、 ERROR、WARNING、INFO、DEBUG
# LOG_LEVEL = 'INFO'

# 文件及路径，log目录需要先建好
today = datetime.datetime.now()
log_file_path = os.path.join(project_dir, 'log') + "/scrapy_{}_{}_{}.log".format(today.year, today.month, today.day)

# 日志输出
# LOG_LEVEL = 'INFO'
LOG_LEVEL = 'DEBUG'
# LOG_LEVEL = 'ERROR'
LOG_FILE = log_file_path

# Obey robots.txt rules
ROBOTSTXT_OBEY = False

# Configure maximum concurrent requests performed by Scrapy (default: 16)
CONCURRENT_REQUESTS = 32

# Configure a delay for requests for the same website (default: 0)
# See https://doc.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
# DOWNLOAD_DELAY = 3
# The download delay setting will honor only one of:
# CONCURRENT_REQUESTS_PER_DOMAIN = 16
# CONCURRENT_REQUESTS_PER_IP = 16

# Disable cookies (enabled by default)
COOKIES_ENABLED = True
COOKIES_DEBUG = True

# Disable Telnet Console (enabled by default)
# TELNETCONSOLE_ENABLED = False

# Override the default request headers:
# DEFAULT_REQUEST_HEADERS = {
#   'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
#   'Accept-Language': 'en',
# }

# Enable or disable spider middlewares
# See https://doc.scrapy.org/en/latest/topics/spider-middleware.html
# SPIDER_MIDDLEWARES = {
#    'scrapy_gif.middlewares.ScrapyGifSpiderMiddleware': 543,
# }

# Enable or disable downloader middlewares
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
# DOWNLOADER_MIDDLEWARES = {
#    'scrapy_gif.middlewares.ScrapyGifDownloaderMiddleware': 543,
# }

# Enable or disable extensions
# See https://doc.scrapy.org/en/latest/topics/extensions.html
# EXTENSIONS = {
#    'scrapy.extensions.telnet.TelnetConsole': None,
# }

# Configure item pipelines
# See https://doc.scrapy.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES = {
    # 'scrapy_gif.pipelines.ScrapyGifPipeline': 300,
    'scrapy_gif.pipelines.MysqlTwistedGifListItemPipeline': 1,
    'scrapy_gif.pipelines.MysqlTwistedGifDetailsPipeline': 2,
}

# Enable and configure the AutoThrottle extension (disabled by default)
# See https://doc.scrapy.org/en/latest/topics/autothrottle.html
# AUTOTHROTTLE_ENABLED = True
# The initial download delay
# AUTOTHROTTLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
# AUTOTHROTTLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each remote server
# AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
# AUTOTHROTTLE_DEBUG = False

# Enable and configure HTTP caching (disabled by default)
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
# HTTPCACHE_ENABLED = True
# HTTPCACHE_EXPIRATION_SECS = 0
# HTTPCACHE_DIR = 'httpcache'
# HTTPCACHE_IGNORE_HTTP_CODES = []
# HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'


# ############################ 配置信息 #############################
# 站点信息
GIF_HOST = 'https://www.gifjia.com/'
TYPE_URL_DIC = {
    '/category/neihan/': '内涵福利',
    '/category/icai/': '动图猜影',
    '/category/meinv/': '美女GIF',
    '/category/thebeauty/': '妹子图',
    '/category/qiuchuchu/': '求出处',
    '/category/hot/': '热门推荐',
    '/category/baike/': '出处大百科',
    '/category/hot/recommended/': '特色专题',
    '/category/movie/': '电影GIF',
    '/category/lieqi/': '猎奇搞笑',
    '/category/movie/gamecartoon/': '游戏动漫',
    '/category/lieqi/baoxiaogif/': '爆笑GIF',
    '/category/hotvideo/': '最热视频',
    '/category/newmovie/': '最新电影',
    '/category/zhainan/': '宅男资讯',
    '/category/yuedu/': '趣味读物',
    '/category/funnews/': '没品新闻',
    '/category/webtui/': '网站推荐',
}

# 配置数据库连接信息
MYSQL_HOST = "localhost"
MYSQL_DBNAME = "gif"
MYSQL_USER = "root"
MYSQL_PASSWORD = "12345678"
MYSQL_PORT = 3306
